class ConfiguratorsController < ApplicationController
	
  skip_before_filter :authorize
  
  # GET /configurators
  # GET /configurators.json
  def index
	current_configurator
    @configurators = Configurator.all
    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @configurators }
    end
  end

  # GET /configurators/1
  # GET /configurators/1.json
  def show
    @configurator = Configurator.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @configurator }
    end
  end

  # GET /configurators/new
  # GET /configurators/new.json
  def new
    @configurator = Configurator.new

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @configurator }
    end
  end

  # GET /configurators/1/edit
  def edit
    @configurator = Configurator.find(params[:id])
  end

  # POST /configurators
  # POST /configurators.json
  def create
    @configurator = Configurator.new(params[:configurator])

    respond_to do |format|
      if @configurator.save
        format.html { redirect_to @configurator, notice: 'Configurator was successfully created.' }
        format.json { render json: @configurator, status: :created, location: @configurator }
      else
        format.html { render action: "new" }
        format.json { render json: @configurator.errors, status: :unprocessable_entity }
      end
    end
  end

  # PUT /configurators/1
  # PUT /configurators/1.json
  def update
    @configurator = Configurator.find(params[:id])

    respond_to do |format|
      if @configurator.update_attributes(params[:configurator])
        format.html { redirect_to @configurator, notice: 'Configurator was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @configurator.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /configurators/1
  # DELETE /configurators/1.json
  def destroy
    @configurator = Configurator.find(params[:id])
    @configurator.destroy

    respond_to do |format|
      format.html { redirect_to configurators_url }
      format.json { head :no_content }
    end
  end

  def download_file
		data = Marshal.dump(Configurator.find(params[:id]))
		file = "educaComp.edc"
		File.open(file, "w"){ |f| f << data }
		send_file( file )
  end
	
	def uploadFile
    post = Upload.save( params[:upload])
		respond_to do |format|
      format.html { redirect_to :action => "upload", :id => post }
      format.json { head :no_content }
    end
  end
end
